var $ = require('../../../utils/helper.js'), that = null
var app = getApp()
Page({
  data: {
    current_index:0,
    error_message:"正在初始化认证",
    ispush:0
  },
  onLoad(e) {
    that = this
    that.setData({pro:e.pro})
  },
  onShow: function () {
    
  },
  onReady: function () {
    $.check(that)
  },
  init: function () {
    $.post("api/auth/get",null,function(data){
      that.setData({ auth: data, error_message:null})
      $.post("api/service/pricelists",null,function(list){
        that.setData({pricelist:list})
      })
    },function(message){
      that.setData({ error_message:message})
    })
  },
  setprice:function(e){
    that.setData({ current_index: e.currentTarget.dataset.index})
  },
  setpush:function(e){
    that.setData({ ispush: e.detail.value.length})
  },
  topay:function(){
    $.post("api/order/buy", { price_index: that.data.current_index, ispush: that.data.ispush, pro: that.data.pro }, function (orderno){
      $.pay("api/order/getpay",{orderno:orderno},function(){
        getApp().toast("支付成功")
        wx.navigateBack({
          
        })    
      },function(){
        getApp().toast("支付失败")     
      })
    })
  }
}) 